//
//  ImageTabbar.m
//  MultiSegmentControl
//
//  Created by ET|冰琳 on 16/7/1.
//  Copyright © 2016年 Ice Butterfly. All rights reserved.
//

#import "ImageTabbar.h"

@interface ImageTabbar ()

@property (nonatomic, strong) NSMutableArray *itemViews;

@end

@implementation ImageTabbar

//- (instancetype)init{
//    if (self = [super init]) {
//        NSLog(@"%@",self);
//    }
//    return self;
//}
//
//- (instancetype)initWithFrame:(CGRect)frame{
//    if (self = [super initWithFrame:frame]) {
//        NSLog(@"%@",self);
//    }
//    return self;
//}

//- (instancetype)initWithCoder:(NSCoder *)aDecoder{
//    if (self = [super initWithCoder:aDecoder]) {
//        NSLog(@"%@",self);
//        [self.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
//    }
//    return self;
//}

- (void)awakeFromNib{
    NSLog(@"self %@",self);
    [self.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    self.backgroundColor = [UIColor lightGrayColor];
    
    for (UITabBarItem *item in self.items) {
        UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
        [button setBackgroundColor:[UIColor redColor]];
        [self addSubview:button];
        [self.itemViews addObject:button];
       
    }
}

- (NSMutableArray *)itemViews{
    if (_itemViews == nil) {
        _itemViews = [NSMutableArray new];
    }
    return _itemViews;
}

- (BOOL)isCustomizing{
    return YES;
}

- (void)beginCustomizingItems:(NSArray<UITabBarItem *> *)items{
    for (UITabBarItem *item in items) {
        UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
        [button setBackgroundColor:[UIColor redColor]];
        [self addSubview:button];
        [self.itemViews addObject:button];
    }
}

//- (BOOL)endCustomizingAnimated:(BOOL)animated{
//    
//}

- (void)layoutSubviews{
    static BOOL odd = true;
    if (odd) {
        odd = false;
        [self printView:self];
    }
    
    self.frame = ({
        CGRect frame = self.frame;
        frame.size.height = 100;
        frame;
    });
    
    UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(200, 0, 100, 100)];
    [button setBackgroundColor:[UIColor redColor]];
    [self addSubview:button];
//    [self.itemViews addObject:button];
}

- (void)printView:(UIView *)view{
    for (UIView *v in view.subviews) {
        NSLog(@"\n\n[self == %@] sub == %@ %p\n\n", [view class], [v class], v);
        [self printView:v];
    }
}

@end
